package cn.hist.hfp.converter;

import cn.hist.hfp.entity.Stray;
import cn.hist.hfp.vo.StrayVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Component
public class StrayConverter {

    public StrayVO convert(Stray stray) {
        return StrayVO.builder().id(stray.getId())
                .id(stray.getId())
                .description(stray.getDescription())
                .image(stray.getImage())
                .userId(stray.getUser().getId())
                .userName(stray.getUser().getName()).build();
    }

    public Set<StrayVO> convert(Set<Stray> strays) {
        Set<StrayVO> strayVOS = new HashSet<>();
        for (Stray stray: strays) {
            strayVOS.add(convert(stray));
        }
        return strayVOS;
    }

    public List<StrayVO> convert(List<Stray> strays) {
        List<StrayVO> strayVOS = new ArrayList<>();
        for (Stray stray: strays) {
            strayVOS.add(convert(stray));
        }
        return strayVOS;
    }
}
